package com.wen.part3;

import java.util.Arrays;

public class Queue<T> {
    private final Object[] queue;
    private final int maxSize;
    private int size = 0;
    private int front = 0;
    private int rear = 0;

    public Queue(int maxSize) {
        queue = new Object[maxSize];
        this.maxSize = maxSize;
    }

    public void offer(T element){
        if (size == maxSize) throw new ArrayIndexOutOfBoundsException();
        queue[size++] = element;
        rear = (rear + 1) % maxSize;
    }

    @SuppressWarnings("unchecked")
    public T poll(){
        if (size == 0) throw new ArrayIndexOutOfBoundsException();
        T data = (T)queue[--size];
        front = (front + 1) % maxSize;
        return data;
    }

    public boolean isEmpty(){
        return size == queue.length;
    }

    public int size(){
        return this.size;
    }

    public static void main(String[] args) {
//        Queue<Integer> integerQueue = new Queue<>(10);
//        for (int i = 0; i < 10; i++) {
//            integerQueue.offer(i);
//        }
//        for (int i = 0; i < 10; i++) {
//            System.out.println(integerQueue.poll());
//        }
        System.out.println(compareVersion("7.5.2.4", "7.5.3"));
    }

    public static int compareVersion(String version1, String version2) {
        int[] a1 = Arrays.stream(version1.split("\\.")).mapToInt(Integer::parseInt).toArray();
        int[] a2 = Arrays.stream(version2.split("\\.")).mapToInt(Integer::parseInt).toArray();
        int i = 0;
        int j = 0;
        while (i < a1.length && j < a2.length){
            if (a1[i] > a2[j]) return 1;
            if (a1[i] < a2[j]) return -1;
            i++;j++;
        }

        while (i < a1.length){
            if (a1[i++] > 0)return 1;
        }
        while (j < a2.length){
            if (a2[j++] > 0)return -1;
        }
        return 0;
    }
}
